/*
 * @Author: silence
 * @Date: 2023-08-28 11:48:12
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-10-18 10:58:40
 * @Description:  益邦配网实现
 */
import 'package:sil_utils_package/tools/SilTools.dart';
import 'package:sil_wifi_yb/sil_wifi_yb.dart';

import 'DeviceNetworkingInterface.dart';
import 'WifiDeviceBackData.dart';

class DeviceNetworkingInterfaceForYB extends DeviceNetworkingInterface {
  final _silWifiYbPlugin = SilWifiYb();
  DeviceNetworkingInterfaceForYB() {}

  @override
  Future<WifiDeviceBackData> checkDeiviceWifiConnectState() async {
    WifiDeviceBackData resultDeviceData = kFailDeviceData;

    Map deviceReturn = await _silWifiYbPlugin.getDeviceInfo() ?? Map();

    if (SilTools.mapIsEmpty(deviceReturn)) {
      /// 提示获取失败
      return resultDeviceData;
    }

    resultDeviceData.code = deviceReturn['code'];
    resultDeviceData.data = deviceReturn['data'];
    resultDeviceData.msg = deviceReturn['msg'];
    return resultDeviceData;
  }

  @override
  Future<WifiDeviceBackData> deiviceSetHomeWifi(
      {required String ssid, required String pwd}) async {
    WifiDeviceBackData resultDeviceData = kFailDeviceData;

    Map deviceReturn =
        await _silWifiYbPlugin.setWifiNetBySsidAndPwd(ssid, pwd) ?? Map();

    if (SilTools.mapIsEmpty(deviceReturn)) {
      return resultDeviceData;
    }

    resultDeviceData.code = deviceReturn['code'];
    resultDeviceData.data = deviceReturn['data'];
    resultDeviceData.msg = deviceReturn['msg'];
    return resultDeviceData;
  }

  @override
  Future<WifiDeviceBackData> deiviceRestart() async {
    WifiDeviceBackData resultDeviceData = kFailDeviceData;

    Map deviceReturn = await _silWifiYbPlugin.restartDevice() ?? Map();

    if (SilTools.mapIsEmpty(deviceReturn)) {
      return resultDeviceData;
    }

    resultDeviceData.code = deviceReturn['code'];
    resultDeviceData.data = deviceReturn['data'];
    resultDeviceData.msg = deviceReturn['msg'];
    return resultDeviceData;
  }

  @override
  Future<WifiDeviceBackData> checkIsSuccess() async {
    WifiDeviceBackData resultDeviceData = kFailDeviceData;

    Map deviceReturn = await _silWifiYbPlugin.getDeviceInfo() ?? Map();

    if (SilTools.mapIsEmpty(deviceReturn)) {
      /// 提示获取失败
      return resultDeviceData;
    }

    resultDeviceData.code = deviceReturn['code'];
    resultDeviceData.data = deviceReturn['data'];
    resultDeviceData.msg = deviceReturn['msg'];
    return resultDeviceData;
  }
}
